<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="新增组装拆卸单">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }

        .layui-table-cell {            overflow: visible !important;        }
        /* 使得下拉框与单元格刚好合适 */
        td .layui-form-select{
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }


        .save{
            cursor:pointer;
        }

        .no-border{
            border: 0 solid #ffffff;
            border-radius: 2px;
            background-color: #ffffff;
        }

        .no-border:hover{
            border: 1px solid #1E9FFF;
            border-radius: 2px;
        }
    </style>

    <script>
        jQuery(function () {
            fixTableOperatorButton();
            $(window).focus();
            window.addEventListener("keydown", function(e) {
                if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
                    $("[lay-filter='save']").click();
                    e.preventDefault();
                }
            }, false);

            getByType("${baseUrl}",ORDER_TYPE.ZCX.type, $("[name='no']"));


            ajaxSelect("${baseUrl}user/user/getAll.action","userId");
            $("[name='date']").val(GMTToDate(new Date()));

            $(".save").click(function (e) {
                $("[lay-filter='save']").click();
                e.preventDefault();
            });


            $(".select-goods-old").click(function () {
                let houseId = $("[name='oldHouseId']").val();
                if (houseId == ""){
                    errTip("请选择出库仓库");
                    return;
                }
                $("#select-goods-type").val("table_old");
                let url = "${baseUrl}select/selectGoods.action?priceFlag=1&numberBar=2&checkStock=1&houseId="+houseId;
                openBigHtmlDialog("选择原商品", url, function (layero, index) {
                    var iframe = window[layero.find('iframe')[0]['name']];
                    iframe.setUsedSnMap(genGoodsSnMap(layui.table.cache['table_old']));
                });
            });

            $(".select-goods-new").click(function () {

                let formData = getFormJson($("#form"));
                let houseId = formData.newHouseId;
                if (houseId == ""){
                    errTip("请选择入库仓库");
                    return;
                }
                $("#select-goods-type").val("table_new");
                let url = "${baseUrl}select/selectGoods.action?priceFlag=1&numberBar=1&houseId="+houseId;
                openBigHtmlDialog("选择新商品", url, function (layero, index) {
                    var iframe = window[layero.find('iframe')[0]['name']];
                    iframe.setUsedSnMap(genGoodsSnMap(layui.table.cache['table_new']));
                });
            });
        });



        layui.use(['form', 'table', 'laydate','ajaxCascader'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                laydate = layui.laydate,
                util = layui.util;
            var cascaderOld = layui.ajaxCascader;

            laydate.render({
                elem: '#date'
            });

            renderTableOld([]);
            renderTableNew([]);

            let option = {
                placeholder:"请选择仓库"
                ,width:160
                , value: "0"
                ,clear:true
                , getChildren: function (value, callback) {
                    var data = [];
                    //表示是门店
                    if (value == "0"){
                        get("${baseUrl}organization/store/getStores.action", function (res) {
                            if (res.code == 1){
                                data = res.data;
                                for (var i in data) {
                                    data[i].value = data[i].id;
                                    data[i].label = data[i].name;
                                    delete data[i].id;
                                    delete data[i].name;
                                    data[i].hasChild = true;
                                }
                                callback(data);
                            }
                        });
                    } else {
                        //表示是仓库
                        get("${baseUrl}organization/house/getHouseByStore.action?storeId="+value, function (res) {
                            if (res.code == 1){
                                if ("${type}" == "1") {
                                    data.push({value:"", label:"全部"});
                                }
                                $.each(res.data, function (i,d) {
                                    data.push({value:d.id, label:d.name, disabled:isTrue(d.locking)});
                                });

                                callback(data);
                            }
                        });
                    }
                }
            };

            get("${baseUrl}organization/house/getDefault.action", function (res) {
                if (res.code == 1 && !res.data.locking){
                    let chooseData = [];
                    chooseData.push(res.data.storeId);
                    chooseData.push(res.data.id);
                    option.chooseData = chooseData;

                    // Ajax传参模式
                    option.elem = "#selectOldHouse";
                    cascaderOld.load(option);
                    $("[name='oldHouseId']").val(res.data.id);

                    $("[name='newHouseId']").attr("storeId",res.data.storeId);
                    $("[name='newHouseId']").attr("old",res.data.id);
                    ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+res.data.storeId, 'newHouseId',null, function (d) {
                        $("[name='newHouseId']").attr("old",d[0].id);
                    });
                }
            });

            option.elem = "#selectOldHouse";
            cascaderOld.load(option);

            // 选择器点击事件的监听
            cascaderOld.on('click', '#selectOldHouse', function(data){
                if (data.disabled) {
                    errTip("该仓库正在盘点，解锁后才能进行业务操作！");
                    $("#selectOldHouse").next().find(".cascader-clear").click();
                    $("[name='oldHouseId']").val('');
                    return;
                }
                let chooseData = cascaderOld.getChooseData();
                if ($("[name='newHouseId']").attr("storeId") != chooseData[0]) {
                    $("[name='newHouseId']").attr("storeId",chooseData[0]);
                    ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+res.data.storeId, 'newHouseId',null, function (d) {
                        $("[name='newHouseId']").attr("old",d[0].id);
                    });

                    $.each(table.cache['table_new'], function (i,d) {
                        if (d.goodsSnList != null) {
                            d.goodsSnList = null;
                        }
                    });
                    renderTableNew(layui.table.cache['table_new']);
                }


                let houseId = data.value;
                let oldOldHouseId = $("[name='oldHouseId']").val();

                $("[name='oldHouseId']").val(houseId);

                if (oldOldHouseId!="" && oldOldHouseId != houseId && table.cache['table_old'].length > 0) {
                    let flag = 1;
                    $.each(table.cache['table_old'], function (i,d) {
                        if (d.goodsSnList != null) {
                            d.goodsSnList = null;
                        }
                    });

                    renderTableOld(layui.table.cache['table_old']);
                }
            });




            table.on('tool(table_old)', function (obj) {
                if (obj.event === 'delete') {
                    let index = $(obj.tr).data('index');
                    table.cache['table_old'].splice(index,1);
                    table.reload('table_old',{data:table.cache['table_old']});
                }
            });

            table.on('tool(table_new)', function (obj) {
                if (obj.event === 'delete') {
                    let index = $(obj.tr).data('index');
                    table.cache['table_new'].splice(index,1);
                    table.reload('table_new',{data:table.cache['table_new']});
                }
            });


            form.on('select(newHouseId)', function (data) {
                if ($("[name='newHouseId']").attr("old") != data.value) {
                    $("[name='newHouseId']").attr("old",data.value)
                    $.each(table.cache['table_new'], function (i,d) {
                        if (d.goodsSnList != null) {
                            d.goodsSnList = null;
                        }
                    });
                    renderTableNew(layui.table.cache['table_new']);
                }
            });

            // 监听修改update到表格中
            form.on('select(unitSelect)', function (data) {
                let index = $(data.elem).parents('tr').data('index');
                let layId = $(data.elem).parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];
                let goodsUnitVo = genUnitVo(tableData[index].goodsUnitVoList, data.value);
                $(data.elem).parents('tr').find(".price").val(getPrice(goodsUnitVo.referBuyPrice));
                $(data.elem).parents('tr').find(".subjectPrice").html("进货价："+getPrice(goodsUnitVo.referBuyPrice));
                $(data.elem).parents('tr').find(".subjectPrice").attr("price",getPrice(goodsUnitVo.referBuyPrice));

                tableData[index].unitId = data.value;
                tableData[index].times = goodsUnitVo.times;
                tableData[index].price = goodsUnitVo.referBuyPrice;
                processAmount($(data.elem));
                processTotalRow();
            });

            form.verify({
                userId: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '经办人不能为空';
                    }
                },
                date: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '业务日期不能为空';
                    }
                }
            });


            form.on('submit(save)',function (data) {
                if (table.cache['table_old'].length == 0) {
                    errTip("请选择原商品清单");
                    return false;
                }

                if (table.cache['table_new'].length == 0) {
                    errTip("请选择新商品清单");
                    return false;
                }

                if (data.field.oldHouseId == ""){
                    errTip("请选择出库仓库");
                    return false;
                }
                if (data.field.newHouseId == ""){
                    errTip("请选择入库仓库");
                    return false;
                }


                let oldTotalAmt = 0;
                let oldTableData = table.cache['table_old'];
                for (let i=0;i<oldTableData.length;i++) {
                    if (oldTableData[i].sn) {
                        if (emptyList(oldTableData[i].goodsSnList)) {
                            errTip("原清单商品("+oldTableData[i].name + ")的序列号数量不能为0");
                            return false;
                        } else if(oldTableData[i].goodsSnList.length != oldTableData[i].number) {
                            errTip("原清单商品("+oldTableData[i].name + ")的序列号数量与数量不一致");
                            return false;
                        }
                    }else {
                        if (oldTableData[i].number == 0) {
                            errTip("原清单商品("+oldTableData[i].name + ")的数量不能为0");
                            return false;
                        }
                    }

                    oldTotalAmt += oldTableData[i].amount;
                }

                let newTotalAmt = 0;
                let newTableData = table.cache['table_new'];
                for (let i=0;i<newTableData.length;i++) {
                    if (newTableData[i].sn) {
                        if (emptyList(newTableData[i].goodsSnList)) {
                            errTip("新清单商品("+newTableData[i].name + ")的序列号数量不能为0");
                            return false;
                        } else if(newTableData[i].goodsSnList.length != newTableData[i].number) {
                            errTip("新清单商品("+newTableData[i].name + ")的序列号数量与数量不一致");
                            return false;
                        }
                    }else {
                        if (newTableData[i].number == 0) {
                            errTip("新清单商品("+newTableData[i].name + ")的数量不能为0");
                            return false;
                        }
                    }
                    newTotalAmt += newTableData[i].amount;
                }

                if (newTotalAmt < oldTotalAmt) {
                    errTip("新商品总金额不能小于原商品总金额，请重新修改");
                    return false;
                }



                //
                let entity = data.field;
                delete entity.number;
                delete entity.unitId;
                delete entity.amount;
                delete entity.price;
                entity.date = genDate(entity.date);
                entity.oldTotalAmt = oldTotalAmt;
                entity.newTotalAmt = newTotalAmt;

                //经货单商品
                let old_list = [];
                $.each(table.cache['table_old'],function (i,d) {
                    let vo = {};
                    vo.goodsId = d.goodsId;
                    vo.unitId = d.unitId;
                    vo.times = d.times;
                    vo.price = d.price;
                    vo.number = d.number;
                    vo.amount = d.amount;
                    vo.remark = d.remark;
                    vo.goodsSnList = genUploadTableList(d.goodsSnList);
                    old_list.push(vo);
                });
                entity.joinSplitOldGoodsVoList = old_list;

                //经货单商品
                let new_list = [];
                $.each(table.cache['table_new'],function (i,d) {
                    let vo = {};
                    vo.goodsId = d.goodsId;
                    vo.unitId = d.unitId;
                    vo.times = d.times;
                    vo.price = d.price;
                    vo.number = d.number;
                    vo.amount = d.amount;
                    vo.remark = d.remark;
                    vo.goodsSnList = genUploadTableList(d.goodsSnList);
                    new_list.push(vo);
                });

                entity.joinSplitNewGoodsVoList = new_list;

                tipLoad("组装拆卸单新增中...");
                post("${baseUrl}house/joinSplit/add.action", entity, function (res) {
                    closeAll();
                    if (res.code == 1) {
                        tip(res.msg);
                        setTimeout(function () {
                            refreshMainIframe("${baseUrl}house/joinSplit.action");
                            closeSubIframe();
                        },1000);
                    } else {
                        errTip(res.msg);
                    }
                });
                return false;
            });
        });

        function renderTableOld(list) {
            layui.table.render({
                id:'table_old',
                elem: '#table_old',
                height: 250,
                data:list,
                totalRow:true,
                text: {
                    none: '请选择商品' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                cols: [[
                    {type:'numbers'},
                    {field: 'name', minWidth: 140, title: '名称/规格',style:"font-size:12px;",templet:function (d) {
                            return genGoodsName(d.name,d.norms)
                        }},
                    {field: 'no', width: 140, title: '商品编号',style:"font-size:12px;"},
                    {field:'number', width: 90, title: '数量',templet:"#numberBar"},
                    {width: 120, title: '单位',style:"font-size:12px;", templet:function (d) {
                            return d.goodsId == null ? "" : genSelectUnit(d.unitId, d.goodsUnitVoList);
                        }},
                    {field: 'price', width: 90, title: '单价',templet:"#priceBar"},
                    {field: 'amount', width: 90, title: '金额',style:"font-size:12px;",templet:"#amountBar"},
                    {width: 110, title: '序列号',templet: "#snNumberBar"},
                    {field: 'remark', width: 120, title: '备注',style:"font-size:12px;",edit:"text"},
                    {title: '操作', minWidth: 70, fixed:'right', templet: '#operBar'},
                ]],
                limit: Number.MAX_VALUE,
                done: function(res, curr, count){
                    processAfterRender($('[lay-id="table_old"]'));
                }
            });
        }


        function renderTableNew(list) {
            layui.table.render({
                id:'table_new',
                elem: '#table_new',
                height: 250,
                data:list,
                totalRow:true,
                text: {
                    none: '请选择商品' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                cols: [[
                    {type:'numbers'},
                    {field: 'name', minWidth: 140, title: '名称/规格',style:"font-size:12px;",templet:function (d) {
                            return genGoodsName(d.name,d.norms)
                        }},
                    {field: 'no', width: 140, title: '商品编号',style:"font-size:12px;"},
                    {field:'number', width: 90, title: '数量',templet:"#numberBar"},
                    {width: 120, title: '单位',style:"font-size:12px;", templet:function (d) {
                            return d.goodsId == null ? "" : genSelectUnit(d.unitId, d.goodsUnitVoList);
                        }},
                    {field: 'price', width: 90, title: '单价',templet:"#priceBar"},
                    {field: 'amount', width: 90, title: '金额',style:"font-size:12px;",templet:"#amountBar"},
                    {width: 110, title: '序列号',templet: "#snNumberBar"},
                    {field: 'remark', width: 120, title: '备注',style:"font-size:12px;",edit:"text"},
                    {title: '操作', minWidth: 70, fixed:'right', templet: '#operBar'},
                ]],
                limit: Number.MAX_VALUE,
                done: function(res, curr, count){
                    processAfterRender($('[lay-id="table_new"]'));
                }
            });
        }

        function processAfterRender($parentTable) {
            $parentTable.find(".snNumberDiv").unbind().bind('click',function () {
                let index = $(this).parents('tr').data('index');
                let layId = $(this).parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];
                showSnList(tableData[index].name, tableData[index].goodsSnList);
            });

            $parentTable.find(".priceDiv").unbind("mouseenter").bind("mouseenter", function() {
                $(this).find(".priceListDiv").css("display","block");
            });
            $parentTable.find(".priceDiv").unbind("mouseleave").bind("mouseleave", function() {
                $(this).find(".priceListDiv").css("display","none");
            });

            $parentTable.find(".subjectPrice").unbind("click").bind("click", function () {
                $(this).parents(".priceDiv").find(".priceListDiv").css("display","none");
                let price = $(this).attr("price");
                $(this).parents(".priceDiv").find(".price").val(price);

                let index = $(this).parents('tr').data('index');
                let layId = $(this).parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];
                tableData[index].price = price;
                processAmount($(this));
                processTotalRow();
            });

            $parentTable.find(".price").unbind("blur").bind("blur",function () {
                $(this).val(getPrice($(this).val()));
                let index = $(this).parents('tr').data('index');
                let layId = $(this).parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];
                tableData[index].price = getPrice($(this).val());
                processAmount($(this));
                processTotalRow();
            });

            $parentTable.find(".amount").unbind("blur").bind("blur",function () {
                setAmount(genAmount($(this).val()), $(this));
                processTotalRow();
            });

            $parentTable.find(".number").unbind("blur").bind("blur",function () {
                let $input=$(this);
                let number = genNumber($input.val());
                checkNumber(number,$input);
                processNumber(number, $input);
                processTotalRow();
            });

            $parentTable.find(".numberSn").unbind("click").bind("click",function () {
                snIndex = $(this).parents('tr').data('index');

                let layId = $(this).parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];

                let goodsId = tableData[snIndex].goodsId;
                let formData = getFormJson($("#form"));
                let houseId = layId=='table_old' ? formData.oldHouseId:formData.newHouseId;
                if (houseId == "" ) {
                    errTip(layId=='table_old' ? "请选择出库仓库":"请选择入库仓库");
                    return;
                }

                let url;
                if(layId=='table_old') {
                    url = "${baseUrl}dialog/sn/select.action?type=2&houseId="+houseId+"&goodsId="+goodsId;
                } else {
                    url = "${baseUrl}dialog/sn/import.action?type=2&houseId="+houseId+"&goodsId="+goodsId;
                }

                openHtmlDialog("管理序列号",url, function (layero, index) {
                    var iframe = window[layero.find('iframe')[0]['name']];
                    let goodsSnList = tableData[snIndex].goodsSnList;
                    if (emptyList(goodsSnList)) {
                        goodsSnList=[];
                    }
                    iframe.setDataToTable(goodsSnList,genGoodsSnMap(tableData));
                });
            });

            processTotalRow();
        }


        /**
         * 开启sn号的商品，选择完序列号会回调这个
         *
         */
        function processSnSelect(data) {
            layui.table.cache[getTableKey()][snIndex].goodsSnList = data;
            let child = data.length + '个';
            let layId = getTableKey();
            let $tr = $('[lay-id="'+layId+'"]').find("tr[data-index='"+snIndex+"']");
            $tr.find(".snNumberDiv").html(child);
            processNumber(data.length, $tr.find(".number"));
            processTotalRow();
            $(window).focus();
        }

        /**
         * 开启sn号的商品，会回调这个函数
         *
         */
        function processSnImport(data) {
            layui.table.cache[getTableKey()][snIndex].goodsSnList = data;
            let child = data.length + '个';
            let $tr = $('[lay-id="'+getTableKey()+'"]').find("tr[data-index='"+snIndex+"']");
            $tr.find(".snNumberDiv").html(child);
            processNumber(data.length, $tr.find(".number"));
            processTotalRow();
            $(window).focus();
        }


        /**
         * 如果使用商品选择窗口，必须实现此函数，否则取不到已选择的商品数据
         * @param data
         */
        function getSelectGoods(data) {
            //处理显示数据
            let tableData = layui.table.cache[getTableKey()];
            $.each(data,function (i,d) {
                d.goodsId = d.id;
                tableData.push(d);

            });
            layui.table.reload(getTableKey(),{data:tableData});
            $(window).focus();
        }

        function processTotalRow() {
            let amount=0;
            let number = 0;
            $.each(layui.table.cache['table_old'], function (i,d) {
                number += parseInt(d.number);
                amount += parseFloat(d.amount);
            });

            setTotalRowWithParent($('[lay-id="table_old"]'),"number",getNumber(number));
            setTotalRowWithParent($('[lay-id="table_old"]'),"amount",getPrice(amount));
            setTotalRowWithParent($('[lay-id="table_old"]'),"1","合计");

            amount=0;
            number = 0;
            $.each(layui.table.cache['table_new'], function (i,d) {
                number += parseInt(d.number);
                amount += parseFloat(d.amount);
            });
            setTotalRowWithParent($('[lay-id="table_new"]'),"number",getNumber(number));
            setTotalRowWithParent($('[lay-id="table_new"]'),"amount",getPrice(amount));
            setTotalRowWithParent($('[lay-id="table_new"]'),"1","合计");
        }

        function checkNumber(number,$input) {
            if (number == 0) {
                errTip("数量必须大于0");
                $input.css("border-color","red");
            } else {
                $input.css("border-color","#ffffff");
            }
        }

        //处理数量空间
        function processNumber(number, $input) {
            if (number == 0) {
                $input.val("");
                $input.html("");
            } else {
                $input.val(getNumber(number));
                $input.html(getNumber(number));
            }

            let layId = $input.parents('.layui-table-view').attr("lay-id");
            let tableData = layui.table.cache[layId];
            let index = $input.parents('tr').data('index');
            tableData[index].number = number;

            //不是整数，但是单位又不支持小数
            let goodsUnitVo = genUnitVo(tableData[index].goodsUnitVoList, tableData[index].unitId);

            if (!isInteger(number) && ((goodsUnitVo.unit.point!=null && !goodsUnitVo.unit.point))){
                errTip("此单位不允许小数，可以在单位中设置");
                $input.val("");
                $input.html("");
                tableData[index].number = 0;
                return;
            }
            processAmount($input);
        }

        function processAmount($tdChild){
            let layId = $tdChild.parents('.layui-table-view').attr("lay-id");
            let tableData = layui.table.cache[layId];
            let index = $tdChild.parents('tr').data('index');
            let number = tableData[index].number;
            if (!isNumber(tableData[index].price)) {
                tableData[index].price = "0";
            }

            let price = parseFloat(tableData[index].price);
            let amount = price * number;
            amount = getPrice(amount);
            setAmount(amount, $tdChild);
        }

        /**
         * 设置金额
         * @param amount
         * @param $tdChild
         */
        function setAmount(amount, $tdChild) {
            layui.use(['form', 'table'], function () {
                let $ = layui.jquery,
                    table = layui.table;
                let layId = $tdChild.parents('.layui-table-view').attr("lay-id");
                let tableData = layui.table.cache[layId];
                let index = $tdChild.parents('tr').data('index');
                tableData[index].amount = amount;
                console.log("amount："+ tableData[index].amount);
                $tdChild.parents('tr').find(".numberDiv .amount").val(getPrice(tableData[index].amount));

                if (tableData[index].amount!=0 && tableData[index].number!=0){
                    tableData[index].price = getPrice(tableData[index].amount/tableData[index].number);
                    $tdChild.parents('tr').find(".priceDiv .price").val(tableData[index].price);
                }
            });
        }

        function getTableKey() {
            return $("#select-goods-type").val();
        }
    </script>

</html:header>
<body style="margin: 0">
<div class="layuimini-container">
    <div class="layuimini-main">
        <h2 class="tableBeforeTitle">组装拆卸单</h2>
        <div style="height: 4px;background-color: #bbbbbb;width: 100%;margin: 10px 0 2px 0;"></div>
        <div style="height: 1px;width: 100%;background-color: #dddddd;margin-bottom: 10px;"></div>

        <input type="hidden" id="select-goods-type">


        <form class="layui-form" action="" lay-filter="form" id="form">
            <input type="hidden" name="close" value="false">
            <input type="hidden" name="oldHouseId" lay-verify="oldHouseId">

            <button style="display: none;" lay-submit lay-filter="save" class="layui-btn">保存</button>

            <div>
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">编号</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" id="no" name="no" class="layui-input readonly" readonly style="font-size: 12px;">
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">业务日期</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="date" id="date" lay-verify="date" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">经手人</div>
                    <div style="display: inline-block;width: 160px;">
                        <select name="userId" lay-verify="userId" lay-filter="userId">
                        </select>
                    </div>
                </div>
            </div>
            <hr>
            <div>
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label" style="font-size:16px;font-weight: bold;">原商品清单</div>

                    <div style="display: inline-block;width: 160px;">
                        <a class="layui-btn select-goods-old">选择原商品</a>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">出库仓库</div>
                    <div style="display: inline-block;width: 160px;">
                        <cascader id="selectOldHouse"></cascader>
                    </div>
                </div>
            </div>
            <div style="margin: -4px 0 0px 0">
                <table class="layui-hide" id="table_old" lay-filter="table_old"></table>
            </div>



            <div>
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label" style="font-size:16px;font-weight: bold;">新商品清单</div>
                    <div style="display: inline-block;width: 160px;">
                        <a class="layui-btn select-goods-new">选择新商品</a>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">入库仓库</div>
                    <div style="display: inline-block;width: 160px;">
                        <select name="newHouseId" lay-filter="newHouseId"></select>
                    </div>
                </div>
            </div>
            <div style="margin: -4px 0 0 0">
                <table class="layui-hide" id="table_new" lay-filter="table_new"></table>
            </div>

            <div style='margin: -10px 0 0 0;'>
                <table class="layui-table">
                    <tbody>
                    <tr>
                    <td>
                        <div style="position: relative;">
                            <input type="text" id="remark" name="remark" class="layui-input no-border" style="padding-left: 60px;">
                            <div style="position: absolute;top: 10px;left: 10px;">
                                备注:
                            </div>
                        </div>
                    </td>
                    <td class="save" style="background-color: #1E9FFF;color:#ffffff;text-align: center;font-size: 16px;">保存(ctrl+s)</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </form>

        <blockquote class="layui-elem-quote layui-text">
            <p style="font-size: 14px;color: #666;font-weight: bold">提示：</p>
            <p style="font-size: 12px;">
                该单据既支持组装商品也支持拆卸商品。
            </p>
            <p style="font-size: 12px;">
                组装商品请在“原商品清单”选择组装的零件商品，在“新商品清单”选择组合后的商品。
            </p>
            <p style="font-size: 12px;">
                拆卸商品请在“原商品清单”选择需要拆卸的商品，在“新商品清单”选择拆卸后的零件商品。
            </p>
        </blockquote>
    </div>

    <script type="text/html" id="operBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
    </script>

    <script type="text/html" id="numberBar" >
        <div class="numberDiv">
            {{# if(d.sn==true){ }}
            <span class="number">{{ getNumber(d.number) }}</span>
            <span class="numberSn">sn</span>
            {{# }else{ }}
            <input type="number" name="number" class="layui-input number" value="{{ getNumber(d.number) }}" style="background: #ffffff">
            {{# } }}
        </div>
    </script>

    <script type="text/html" id="snNumberBar" >
        {{# if(d.sn==true){ }}
        {{# if(d.goodsSnList!=null && d.goodsSnList.length > 0){ }}
        <div class="snNumberDiv">{{d.goodsSnList.length}}个</div>
        {{# }else{ }}
        <div class="snNumberDiv"></div>
        {{# } }}
        {{# } }}
    </script>

    <script type="text/html" id="amountBar" >
        <div class="numberDiv">
            <input type="number" name="amount" value="{{ getPrice(d.amount) }}" class="layui-input amount">
        </div>
    </script>

    <script type="text/html" id="priceBar" >
        <div class="priceDiv">
            <input type="number" name="price" value="{{ getPrice(d.price) }}" class="layui-input price">

            <div class="priceListDiv">
                <ul>
                    {{# if(d.unitId!=undefined){ }}
                    <li class="subjectPrice" price="{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).referBuyPrice) }}">
                        进货价:{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).referBuyPrice) }}
                    </li>
                    {{# } }}
                </ul>
            </div>
        </div>
    </script>


</div>

</body>
<html:snListDialog/>
<html:loading/>
</html>